package com.example.blogdemo.common.advice;


import com.example.blogdemo.common.exception.BlogException;
import com.example.blogdemo.pojo.respond.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@Slf4j
@ResponseBody
@ControllerAdvice
public class ExceptionAdvice {

//    @ExceptionHandler
//    public Result exceptionHandler(Exception exception) {
//        log.error("发生异常，e:", exception.getMessage());
//        return Result.fail(exception.getMessage());
//    }

    @ExceptionHandler
    public Result blogException(BlogException blogException) {
        log.error("发生异常，e:", blogException.getErrMsg());
        return Result.fail(blogException.getErrMsg());
    }
}
